package com.skyolder.milkbee.repository;

import com.skyolder.milkbee.domain.Message;
import com.skyolder.milkbee.dto.MyMessage;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;

import java.util.List;

/**
 * Spring Data JPA repository for the Message entity.
 */
@SuppressWarnings("unused")
public interface MessageRepository extends JpaRepository<Message,Long> {
	
	@Query("select new com.skyolder.milkbee.dto.MyMessage(m.id,fu.login,tu.login,fu.id,tu.id,m.content,m.createdAt) from Message as m,User as fu,User as tu where (m.toUserId=?1 or m.fromUserId=?1) and m.toUserId=tu.id and m.fromUserId=fu.id ")
	Page<MyMessage> doQueryMyMessages(Long userId, Pageable pageable);

}
